package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/*
 调用有参方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        //say(String info)
        Method say = cls.getMethod("say", String.class);
        say.invoke(obj,"hello world!");

        //say(String info,int count)
        Method say1 = cls.getMethod("say", String.class, int.class);
        say1.invoke(obj,"hello,world!",5);
    }
}
